" plug-vim config
""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
call plug#begin('~/.local/share/nvim/plugged')
    " Declare the list of plugins.
    Plug 'https://gitee.com/cangmj/mason.nvim.git', {'tag':'stable'}
    Plug 'https://gitee.com/cangmj/mason-lspconfig.nvim.git', {'tag':'stable'}
    Plug 'https://gitee.com/cangmj/nvim-lspconfig.git', {'tag':'v2.4.0'}
    Plug 'https://gitee.com/cangmj/cmp-nvim-lsp.git'
    Plug 'https://gitee.com/cangmj/cmp-buffer.git'
    Plug 'https://gitee.com/cangmj/cmp-path.git'
    Plug 'https://gitee.com/cangmj/cmp-cmdline.git'
    Plug 'https://gitee.com/cangmj/nvim-cmp.git'
    Plug 'https://gitee.com/cangmj/cmp-vsnip.git'
    Plug 'https://gitee.com/william135/vim-vsnip.git'
    Plug 'https://gitee.com/cangmj/nvim-autopairs.git'
    " Plug 'https://gitee.com/cangmj/ultimate-autopair.nvim.git', {'branch':'v0.6'}
    "
    Plug 'https://gitee.com/cangmj/nvim-treesitter.git', {'tag':'v0.10.0', 'do':':TSUpdate'}
    " Plug 'https://gitee.com/cangmj/nvim-treesitter-textobjects.git'
    " Plug 'https://gitee.com/cangmj/nvim-ts-rainbow.git'
    Plug 'https://gitee.com/cangmj/nvim-ts-context-commentstring.git'
    Plug 'https://gitee.com/cangmj/hlargs.nvim.git'
    Plug 'https://gitee.com/cangmj/nvim-surround.git', {'tag':'v2.1.4'}
    " Plug 'https://gitee.com/cangmj/pretty-fold.nvim.git'
    Plug 'https://gitee.com/cangmj/lualine.nvim.git'
    Plug 'https://gitee.com/cangmj/bufferline.nvim.git', {'tag':'v4.6.1'}
    Plug 'https://gitee.com/cangmj/telescope.nvim.git', {'tag':'0.1.8'}
    Plug 'https://gitee.com/cangmj/indent-blankline.nvim.git', {'tag':'v3.5.2'}
    Plug 'https://gitee.com/cangmj/gitsigns.nvim.git', {'tag':'release'}
    Plug 'https://gitee.com/cangmj/nvim-tree.lua.git'
    Plug 'https://gitee.com/cangmj/nvim-web-devicons.git'
    " Plug 'https://gitee.com/cangmj/plenary.nvim.git'
    Plug 'https://gitee.com/cangmj/tabular.git'
    " Plug 'https://gitee.com/cangmj/symbols-outline.nvim.git'
    Plug 'https://gitee.com/cangmj/outline.nvim.git'
    Plug 'https://gitee.com/cangmj/leap.nvim.git'
    " Plug 'https://gitee.com/cangmj/flit.nvim.git'
    Plug 'https://gitee.com/cangmj/Comment.nvim.git', {'tag':'v0.8.0'}
    " Plug 'https://gitee.com/cangmj/animation.nvim.git'
    Plug 'https://gitee.com/cangmj/middleclass.git'
    Plug 'https://gitee.com/cangmj/windows.nvim.git'
    Plug 'https://gitee.com/cangmj/nvim-notify.git', {'tag':'v3.13.5'}
    " Plug 'https://gitee.com/cangmj/nvim-lsp-notify.git', {'tag':'1.0.0'}
    " Plug 'https://gitee.com/cangmj/lsp-format.nvim.git'

    Plug 'https://gitee.com/cangmj/kanagawa.nvim.git'
    " Plug 'https://gitee.com/cangmj/material.nvim.git'
call plug#end()

""""""""""""""""""""""""""""""
" custom config
""""""""""""""""""""""""""""""
" let g:loaded_netrw       = 1
" let g:loaded_netrwPlugin = 1

autocmd BufWritePre * :%s/\s\+$//e

set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gbk
set ff=unix
"set softtabstop=4
"set tabstop=4
"set shiftwidth=4
"set expandtab
set cc=120

set nu rnu
set cursorline
"set cursorcolumn

set autochdir
" press shift let terminal mouse active
set mouse=r
" set mouse=

" custom key map
noremap! <A-`> <Esc>
noremap <A-`> <Esc>

set termguicolors
" set term=xterm
" set t_Co=256
set selection=exclusive
set selectmode=mouse,key
set mousemodel=popup
set keymodel=startsel,stopsel

"=============================
" native lsp + cmp
"=============================
lua << EOF
vim.opt.completeopt = {'menu', 'menuone', 'noselect'}

require("mason").setup()
require("mason-lspconfig").setup()

-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', 'gp', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', 'gn', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)

-- cmp config
local t = function(str)
  return vim.api.nvim_replace_termcodes(str, true, true, true)
end

-- local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require('cmp')

cmp.setup({
  snippet = {
    -- REQUIRED - you must specify a snippet engine
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
      -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
      -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
      -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
    end,
  },
  window = {
    completion = cmp.config.window.bordered(),
    documentation = cmp.config.window.bordered(),
  },
  formatting = {
    fields = {'menu', 'abbr', 'kind'},
    format = function(entry, item)
      local menu_icon = {
        nvim_lsp = 'λ',
        vsnip = '⋗',
        buffer = 'Ω',
        path = '🖫',
      }

      item.menu = menu_icon[entry.source.name]
      return item
    end,
  },
  mapping = cmp.mapping.preset.insert({
    ['<C-b>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-n>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.abort(),
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<Tab>'] = cmp.mapping(function(fallback)
      local col = vim.fn.col('.') - 1

      if cmp.visible() then
        cmp.select_next_item(select_opts)
      elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
        fallback()
      else
        cmp.complete()
      end
    end, {'i', 's'}),
    ['<Up>'] = cmp.mapping.select_prev_item(select_opts),
    ['<Down>'] = cmp.mapping.select_next_item(select_opts),
  }),
  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
    { name = 'vsnip' }, -- For vsnip users.
    -- { name = 'luasnip' }, -- For luasnip users.
    -- { name = 'ultisnips' }, -- For ultisnips users.
    -- { name = 'snippy' }, -- For snippy users.
  }, {
    { name = 'buffer' },
  })
})
-- Set configuration for specific filetype.
--cmp.setup.filetype('gitcommit', {
--  sources = cmp.config.sources({
--    { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
--  }, {
--    { name = 'buffer' },
--  })
--})

-- Use buffer source foj `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
  completion = { autocomplete = false },
  sources = {
    { name = 'buffer' }
  }
})

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
  completion = { autocomplete = false },
  sources = cmp.config.sources({
    { name = 'path' }
  }, {
    { name = 'cmdline' }
  })
})

-- autopairs
-- cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({  map_char = { tex = '' } }))
-- add a lisp filetype (wrap my-function), FYI: Hardcoded = { "clojure", "clojurescript", "fennel", "janet" }
-- cmp_autopairs.lisp[#cmp_autopairs.lisp+1] = "racket"

-- Set up lspconfig.
local lspconfig = require("lspconfig")
local capabilities = vim.lsp.protocol.make_client_capabilities()
--capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)

-- lsp-format
-- require("lsp-format").setup {}

-- config on_attch and lsp_flags
local function on_attach(client, bufnr)
  -- Mappings.
  local bufopts = { noremap=true, silent=true, buffer=bufnr }
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
  vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
  vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
  vim.keymap.set('n', 'gh', vim.lsp.buf.hover, bufopts)
  -- vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
  -- vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
  vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)

  -- lsp-format
  -- require("lsp-format").on_attach(client, bufnr)
end

local lsp_flags = {
  debounce_text_changes = 100,
}

-- language server
require('lspconfig').clangd.setup{
  on_attach = on_attach,
  flags = lsp_flags,
  capabilities = capabilities,
  cmd = {
    "clangd",
    "--background-index",
  },
  filetypes = { "c", "cpp", "objc", "objcpp" },
}
require('lspconfig').pyright.setup{
  on_attach = on_attach,
  flags = lsp_flags,
  capabilities = capabilities,
}
require('lspconfig').gopls.setup{
  on_attach = on_attach,
  flags = lsp_flags,
  capabilities = capabilities,
}
require('lspconfig').bashls.setup{
  on_attach = on_attach,
  flags = lsp_flags,
  capabilities = capabilities,
}
-- require('lspconfig').lua_ls.setup{
--   on_attach = on_attach,
--   flags = lsp_flags,
--   capabilities = capabilities,
-- }
require('lspconfig').vimls.setup{
  on_attach = on_attach,
  flags = lsp_flags,
  capabilities = capabilities,
}

-- setup format keymap
-- vim.api.nvim_set_keymap("n", "<leader><leader>f", "<Cmd>Format<CR>", {noremap = true, silent = true})

-- Diagnostic config
local sign = function(opts)
  vim.fn.sign_define(opts.name, {
    texthl = opts.name,
    text = opts.text,
    numhl = ''
  })
end

sign({name = 'DiagnosticSignError', text = '✘'})
sign({name = 'DiagnosticSignWarn', text = '▲'})
sign({name = 'DiagnosticSignHint', text = '⚑'})
sign({name = 'DiagnosticSignInfo', text = ''})
EOF

"=============================
" lualine bufferline
"=============================
set guioptions-=e " Use showtabline in gui vim
set sessionoptions+=tabpages,globals " store tabpages and globals in session
lua << EOF
require('nvim-web-devicons').setup {
  -- your personnal icons can go here (to override)
  -- you can specify color or cterm_color instead of specifying both of them
  -- DevIcon will be appended to `name`
  override = {
  };
  -- globally enable different highlight colors per icon (default to true)
  -- if set to false all icons will have the default icon's color
  color_icons = true;
  -- globally enable default icons (default to false)
  -- will get overriden by `get_icons` option
  default = true;
}

require("bufferline").setup {
  options = {
    themable = false,
    numbers = "ordinal",
    tab_size = 15,
    max_name_length = 15,
    --
    diagnostics = "nvim_lsp",
    diagnostics_indicator = function(count, level, diagnostics_dict, context)
      return "("..count..")"
    end,
    indicator = {
      icon = "▊",
      style = 'icon',
    },
    show_buffer_close_icons = false,
    show_close_icons = false,
    show_tab_indicators = true,
    --hover = {
    --  enabled = true,
    --  delay = 200,
    --  reveal = {'close'}
    --},
  },
  highlights = {
    indicator_selected = {
      fg = "#64c1ff",
    },
    close_button_selected = {
      fg = "#64c1ff",
    },
  },
}

vim.api.nvim_set_keymap("n", "<leader>cc", "<Cmd>bdelete<CR>", {noremap = true, silent = true})

vim.api.nvim_set_keymap("n", "gb", "<Cmd>BufferLinePick<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "gt", "<Cmd>BufferLineCycleNext<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "gT", "<Cmd>BufferLineCyclePrev<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "<A-.>", "<Cmd>BufferLineMoveNext<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "<A-,>", "<Cmd>BufferLineMovePrev<CR>", {noremap = true, silent = true})

vim.api.nvim_set_keymap("n", "1gt", "<Cmd>BufferLineGoToBuffer 1<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "2gt", "<Cmd>BufferLineGoToBuffer 2<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "3gt", "<Cmd>BufferLineGoToBuffer 3<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "4gt", "<Cmd>BufferLineGoToBuffer 4<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "5gt", "<Cmd>BufferLineGoToBuffer 5<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "6gt", "<Cmd>BufferLineGoToBuffer 6<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "7gt", "<Cmd>BufferLineGoToBuffer 7<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "8gt", "<Cmd>BufferLineGoToBuffer 8<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "9gt", "<Cmd>BufferLineGoToBuffer 9<CR>", {noremap = true, silent = true})

require('lualine').setup {
  options = {
    icons_enabled = true,
    theme = 'auto',
    -- section_separators = { left = '', right = ''},
    -- component_separators = { left = '', right = ''},
    disabled_filetypes = {
      statusline = {},
      winbar = {},
    },
    ignore_focus = {},
    always_divide_middle = false,
    globalstatus = false,
    refresh = {
      statusline = 1000,
      winbar = 1000,
    }
  },
  sections = {
    lualine_a = {
      {
        'mode',
        icons_enabled = true, -- Enables the display of icons alongside the component.
        -- icon position can also be set to the right side from table. Example:
        -- {'branch', icon = {'', align='right', color={fg='green'}}}
        icon = nil,

        separator = nil,      -- Determines what separator to use for the component.
        cond = nil,           -- Condition function, the component is loaded when the function returns `true`.
        -- Defines a custom color for the component:
        color = nil, -- The default is your theme's color for that section and mode.
        -- Specify what type a component is, if omitted, lualine will guess it for you.
        type = nil,

        padding = 1, -- Adds padding to the left and right of components.
        fmt = nil,   -- Format function, formats the component's output.
        on_click = nil, -- takes a function that is called when component is clicked with mouse.
      }
    },
    lualine_b = {
      'branch',
      {
        'diff',
        colored = true, -- Displays a colored diff status if set to true
        diff_color = {
          -- Same color values as the general color option can be used here.
          added    = 'DiffAdd',    -- Changes the diff's added color
          modified = 'DiffChange', -- Changes the diff's modified color
          removed  = 'DiffDelete', -- Changes the diff's removed color you
        },
        symbols = {added = '+', modified = '~', removed = '-'}, -- Changes the symbols used by the diff.
        source = nil, -- A function that works as a data source for diff.
      },
      {
        'diagnostics',
        sources = {'nvim_diagnostic'},
        sections = { 'error', 'warn', 'info', 'hint' },
        diagnostics_color = {
          -- Same values as the general color option can be used here.
          error = 'DiagnosticError', -- Changes diagnostics' error color.
          warn  = 'DiagnosticWarn',  -- Changes diagnostics' warn color.
          info  = 'DiagnosticInfo',  -- Changes diagnostics' info color.
          hint  = 'DiagnosticHint',  -- Changes diagnostics' hint color.
        },
        symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'},
        colored = true,           -- Displays diagnostics status in color if set to true.
      }
    },
    lualine_c = {
      {
        'filename',
        file_status = true,      -- Displays file status (readonly status, modified status)
        newfile_status = false,  -- Display new file status (new file means no write after created)
        path = 3,                -- 0: Just the filename
                                 -- 1: Relative path
                                 -- 2: Absolute path
                                 -- 3: Absolute path, with tilde as the home directory

        shorting_target = 40,    -- Shortens path to leave 40 spaces in the window
                                 -- for other components. (terrible name, any suggestions?)
        symbols = {
          modified = '[+]',      -- Text to show when the file is modified.
          readonly = '[-]',      -- Text to show when the file is non-modifiable or readonly.
          unnamed = '[No Name]', -- Text to show for unnamed buffers.
          newfile = '[New]',     -- Text to show for new created file before first writting
        }
      }
    },
    lualine_x = {'encoding',
      {
        'fileformat',
        symbols = {
          unix = '', -- e712
          dos = '',  -- e70f
          mac = '',  -- e711
        },
      },
      {
        'filetype',
        colored = true,   -- Displays filetype icon in color if set to true
        icon_only = false, -- Display only an icon for filetype
        icon = { align = 'right' }, -- Display filetype icon on the right hand side
        -- icon =    {'X', align='right'}
        -- Icon string ^ in table is ignored in filetype component
      }
    },
    lualine_y = {'progress'},
    lualine_z = {'location', "os.date('%Y%m%d %H:%M')"}
  },
  inactive_sections = {
    lualine_a = {},
    lualine_b = {},
    lualine_c = {'filename'},
    lualine_x = {'location'},
    lualine_y = {},
    lualine_z = {}
  },
  winbar = {},
  inactive_winbar = {},
  extensions = {}
}
EOF

"=============================
" outline
"=============================
lua << EOF
vim.keymap.set("n", "<leader>o", "<cmd>Outline<CR> | <cmd>NvimTreeClose<CR>", { desc = "Toggle Outline" })
require("outline").setup {
    -- Your setup opts here (leave empty to use defaults)
    outline_window = {
        width = 25,
        relative_with = true,
        show_relative_numbers = true,
    }
}
EOF

"=============================
" telescope
"=============================
" Using Lua functions
lua << EOF
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff',  builtin.find_files, {})
vim.keymap.set('n', '<leader>flg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb',  builtin.buffers, {})
vim.keymap.set('n', '<leader>fh',  builtin.help_tags, {})
-- git
vim.keymap.set('n', '<leader>fgc', builtin.git_commits, {})
vim.keymap.set('n', '<leader>fgs', builtin.git_status, {})
EOF

"=============================
" notify
"=============================
lua << EOF
require("notify").setup {
  stages = 'fade_in_slide_out',
  background_colour = 'FloatShadow',
  timeout = 4000,
}
-- vim.notify = require('notify')
-- require("lsp-notify").setup {
--     notify = vim.notify
-- }
EOF

"=============================
" nvim-tree
"=============================
lua << EOF
local function nvt_attach(bufnr)
  local api = require "nvim-tree.api"
  local function opts(desc)
    return {desc = "nvim-tree: " .. desc, buffer=bufnr, noremap=true, silent=true, nowait=true}
  end
  --
  api.config.mappings.default_on_attach(bufnr)
  --
  vim.keymap.set('n', 'h', api.node.navigate.parent, opts('Parent'))
  vim.keymap.set('n', 'l', api.node.open.preview, opts('Preview'))
  vim.keymap.set('n', 'u', api.tree.change_root_to_parent, opts('Up'))
  vim.keymap.set('n', 't', api.node.open.edit, opts('Open: Edit'))
  vim.keymap.set('n', 'o', api.tree.change_root_to_node, opts('CD'))
  vim.keymap.set('n', 'v', api.node.open.vertical, opts('Open: VSplit'))
end

require("nvim-tree").setup {
  on_attach = nvt_attach,
  sort = {
    sorter = "case_sensitive",
  },
  view = {
    side = "right",
    width = "25%",
    -- adaptive_size = true,
    -- mappings = {
    --   list = {
    --     { key = "u", action = "dir_up" },
    --     { key = "t", action = "tabnew" },
    --     { key = "v", action = "vsplit" },
    --   },
    -- },
  },
  renderer = {
    group_empty = true,
  },
  filters = {
    dotfiles = true,
  },
}

-- nvim-tree key map
vim.api.nvim_set_keymap("n", "<leader>nn", "<Cmd>NvimTreeToggle<CR> | <Cmd>OutlineClose<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "<leader>nb", "<Cmd>NvimTreeFocus<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "<leader>nf", "<Cmd>NvimTreeFindFile<CR>", {noremap = true, silent = true})
EOF

"=============================
" gitsigns
"=============================
lua << EOF
require('gitsigns').setup {
}
EOF

"=============================
" tabular
"=============================
noremap <leader>tae :Tabularize/=<cr>
noremap <leader>tap :Tabularize/-><cr>
noremap <leader>tad :Tabularize/\.<cr>
noremap <leader>taq :Tabularize/'<cr>
noremap <leader>tacm :Tabularize/,<cr>
noremap <leader>taco :Tabularize/:<cr>

"=============================
" nvim-surround
"=============================
" Old text                    Command         New text
" -------------------------------------------------------------------
" surr*ound_words             ysiw)           (surround_words)
" *make strings               ys$"            "make strings"
" [delete ar*ound me!]        ds]             delete around me!
" remove <b>HTML t*ags</b>    dst             remove HTML tags
" 'change quot*es'            cs'"            "change quotes"
" <b>or tag* types</b>        csth1<CR>       <h1>or tag types</h1>
" delete(functi*on calls)     dsf             function calls
lua << EOF
require("nvim-surround").setup()
EOF

"=============================
" treesitter
"=============================
lua << EOF
require('nvim-treesitter.configs').setup {
  -- A list of parser names, or "all"
  ensure_installed = { "c" },
  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,
  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,
  -- List of parsers to ignore installing (for "all")
  ignore_install = { },

  ---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
  -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
  highlight = {
    -- `false` will disable the whole extension
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = { },
    -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
    disable = function(lang, buf)
        local max_filesize = 100 * 1024 -- 100 KB
        local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
        if ok and stats and stats.size > max_filesize then
            return true
        end
    end,

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
  incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = '<CR>',
      node_incremental = '<CR>',
      node_decremental = '<BS>',
      scope_incremental = '<TAB>',
    }
  },
  -- 启用基于Treesitter的代码格式化(=) . NOTE: This is an experimental feature.
  indent = {
    enable = false
  },
  rainbow = {
    enable = true
  --   -- disable = { "jsx", "cpp" }, list of languages you want to disable the plugin for
  --   extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
  --   max_file_lines = nil, -- Do not enable for files with more than n lines, int
  --   colors = { "#00ff00", "#ffff00", "#ff7f00", "#1e90ff", "#ff0000", "#9400d3" }, -- table of hex strings
  --   -- termcolors = {} -- table of colour name strings
  }
  -- context_commentstring = {
  --   enable = true,
  --   enable_autocmd = false,
  -- }
}
-- for treesitter-based folding
-- vim.opt.foldlevel = 20
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
-- vim.opt.foldtext = "nvim_treesitter#foldtext()"

-- require('pretty-fold').setup {
--   -- fill_char = ' ',
--   -- remove_fold_marker = false,
--   process_comment_signs = false,
--   -- comment_signs = {
--   --   {'/**', '*/'}, -- C++ Doxygen comments
--   -- },
--   -- stop_words = {
--   --    -- ╟─ "*" ──╭───────╮── "@brief" ──╭───────╮──╢
--   --    --          ╰─ WSP ─╯              ╰─ WSP ─╯
--   --    '%*%s*@brief%s*',
--   -- },
-- }

-- hlargs for treesitter
require('hlargs').setup()

EOF
"require("nvim-treesitter.install").prefer_git = true
"=============================
" Comment.nvim
"=============================
lua << EOF
require('Comment').setup {
  padding = true,
  sticky = true,
  ignore = nil,
  ---LHS of toggle mappings in NORMAL mode
  toggler = {
    line = 'gcc',
    block = 'gbc',
  },
  ---LHS of operator-pending mappings in NORMAL and VISUAL mode
  opleader = {
    line = 'gc',
    block = 'gb',
  },
  ---LHS of extra mappings
  extra = {
    above = 'gcO',
    below = 'gco',
    eol = 'gcA',
  },
  ---Enable keybindings
  ---NOTE: If given `false` then the plugin won't create any mappings
  mappings = {
    basic = true,
    extra = true,
  },
  ---Function to call before (un)comment
  pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
  ---Function to call after (un)comment
  post_hook = nil,
}
EOF

"=============================
" indent-blankline
"=============================
lua << EOF
-- vim.opt.fillchars:append({
--     horiz     = '━',
--     horizdown = '┳',
--     horizup   = '┻',
--     vert      = '┃',
--     vertleft  = '┫',
--     vertright = '┣',
--     verthoriz = '╋',
-- })

local highlight = {
    "RainbowRed",
    "RainbowYellow",
    "RainbowBlue",
    "RainbowOrange",
    "RainbowGreen",
    "RainbowViolet",
    "RainbowCyan",
}

local hooks = require "ibl.hooks"
-- create the highlight groups in the highlight setup hook, so they are reset
-- every time the colorscheme changes
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
    vim.api.nvim_set_hl(0 , "RainbowRed"    , { fg = "#E06C75" })
    vim.api.nvim_set_hl(0 , "RainbowYellow" , { fg = "#E5C07B" })
    vim.api.nvim_set_hl(0 , "RainbowBlue"   , { fg = "#61AFEF" })
    vim.api.nvim_set_hl(0 , "RainbowOrange" , { fg = "#D19A66" })
    vim.api.nvim_set_hl(0 , "RainbowGreen"  , { fg = "#98C379" })
    vim.api.nvim_set_hl(0 , "RainbowViolet" , { fg = "#C678DD" })
    vim.api.nvim_set_hl(0 , "RainbowCyan"   , { fg = "#56B6C2" })
end)

-- vim.g.rainbow_delimiters = { highlight = highlight }
require("ibl").setup {
    indent = { highlight = highlight }
}
hooks.register(hooks.type.SCOPE_HIGHLIGHT, hooks.builtin.scope_highlight_from_extmark)
EOF

"=============================
" windows.nvim
"=============================
lua << EOF
vim.o.winwidth = 10
vim.o.winminwidth = 10
vim.o.equalalways = false
require('windows').setup {
  autowidth = {
    enable = true,
    winwidth = 0.65,
  },
  ignore = {
    buftype = { "quickfix", "nofile" },
    filetype = { "NvimTree", "Outline" },
  },
  animation = {
    enable = false,
    duration = 200,
    fps = 60,
    easing = "in_out_sine"
  }
}

vim.keymap.set('n', '<C-w>z', "<Cmd>WindowsMaximize<CR>")
vim.keymap.set('n', '<C-w>_', "<Cmd>WindowsMaximizeVertically<CR>")
vim.keymap.set('n', '<C-w>|', "<Cmd>WindowsMaximizeHorizontally<CR>")
vim.keymap.set('n', '<C-w>=', "<Cmd>WindowsEqualize<CR>")
EOF

"=============================
" hop.nvim
"=============================
lua << EOF
require('leap').add_default_mappings()
--require('leap').opts.highlight_unlabeled_phase_one_targets = true
vim.keymap.set({'x', 'o', 'n'}, '<leader><leader>j', '<Plug>(leap-forward-to)')
vim.keymap.set({'x', 'o', 'n'}, '<leader><leader>k', '<Plug>(leap-backward-to)')

--require('flit').setup {
--  keys = { f = 'f', F = 'F', t = 't', T = 'T' },
--  -- A string like "nv", "nvo", "o", etc.
--  labeled_modes = "v",
--  multiline = true,
--  -- Like `leap`s similar argument (call-specific overrides).
--  -- E.g.: opts = { equivalence_classes = {} }
--  opts = {}
--}

-- autopairs
require("nvim-autopairs").setup {
  fast_wrap = {
    map = "<M-e>",
    chars = { "{", "[", "(", '"', "'" },
    pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
    offset = 0, -- Offset from pattern match
    end_key = "$",
  },
}
-- local Rule = require('nvim-autopairs.rule')
-- local npairs = require('nvim-autopairs')
-- npairs.add_rules(
--   Rule("{", "}")
-- )
-- npairs.setup()
-- require("ultimate-autopair").setup {}
EOF

"=============================
" color scheme
"=============================
lua << EOF
require('kanagawa').load("wave")
-- vim.cmd("colorscheme kanagawa-dragon")

-- vim.g.material_style = "deep ocean"
-- vim.g.material_style = "darker"
-- require('material').setup({
--     plugins = { -- Uncomment the plugins that you use to highlight them
--         -- Available plugins:
--         -- "dap",
--         -- "dashboard",
--         "gitsigns",
--         "hop",
--         "indent-blankline",
--         -- "lspsaga",
--         -- "mini",
--         -- "neogit",
--         -- "neorg",
--         "nvim-cmp",
--         -- "nvim-navic",
--         "nvim-tree",
--         "nvim-web-devicons",
--         -- "sneak",
--         "telescope",
--         -- "trouble",
--         -- "which-key",
--     },
--     high_visibility = {
--         lighter = false, -- Enable higher contrast text for lighter style
--         darker = true -- Enable higher contrast text for darker style
--     },
--     lualine_style = "default", -- Lualine style ( can be 'stealth' or 'default' )
--     async_loading = true, -- Load parts of the theme asyncronously for faster startup (turned on by default)
--     custom_colors = nil, -- If you want to everride the default colors, set this to a function
--     custom_highlights = {}, -- Overwrite highlights with your own
-- })
-- vim.cmd 'colorscheme material'
EOF

